package com.tiezhu.stream;

import java.util.ArrayList;
import java.util.List;

public class StreamDemo {
    public static void main(String[] args) {
        List<String> stringCollection = new ArrayList<>();
        stringCollection.add("ddd2");
        stringCollection.add("aaa2");
        stringCollection.add("bbb1");
        stringCollection.add("aaa1");
        stringCollection.add("bbb3");
        stringCollection.add("ccc");
        stringCollection.add("bbb2");
        stringCollection.add("ddd1");
        streamMap(stringCollection);
        streamMatch(stringCollection);
        streamCount(stringCollection);
    }

    /**
     * stream流大写转换
     * @param stringCollection
     */
    public static void streamMap(List<String> stringCollection) {
        stringCollection.stream()
                .map(String::toUpperCase)
                .sorted()
                .forEach(System.out::println);
    }
    /**
     * stream流过滤器
     * @param stringCollection
     */
    public static void streamFilter(List<String> stringCollection) {
        stringCollection.stream()
                .filter(s -> s.startsWith("a"))
                .sorted()
                .forEach(System.out::println);
    }

    /**
     * stream流计数器
     * @param stringCollection
     */
    public static void streamCount(List<String> stringCollection) {
        long a = stringCollection.stream()
                .filter(s -> s.startsWith("a"))
                .count();
        System.out.println("count=> "+a);
    }


    /**
     * stream流匹配
     * @param stringCollection
     */
    public static void streamMatch(List<String> stringCollection) {
        boolean a = stringCollection.stream()
                .anyMatch(s -> s.startsWith("a"));
        boolean b = stringCollection.stream()
                .allMatch(s -> s.startsWith("a"));
        boolean c = stringCollection.stream()
                .noneMatch(s -> s.startsWith("z"));
        System.out.println(a+"-"+b+"-"+c);
    }
}
